#include "LineSelectionWhiteboard.h"
#include "utility.h"

// Initialize the LineSelectionWhiteboard object
LineSelectionWhiteboard::LineSelectionWhiteboard(int num){
	currLineLength = new int[num];
	lineOpen = new int[num];
	numReshuffle = 0;
	for (int i = 0; i < num; i++) {
		currLineLength[i] = 0;
		lineOpen[i] = 1;
	}
	numLines = num;
	
	//
	//lineOpen[1] = 0;
}

// De-allocate LineSelectionWhiteboard			
LineSelectionWhiteboard::~LineSelectionWhiteboard(){
	
}			

// returns the number of active lines for the simulation
int LineSelectionWhiteboard::getNumLines() {
	return numLines;
}

// returns the length of a specific line
int LineSelectionWhiteboard::getLineLength(int lineNum){
	return currLineLength[lineNum];
} 	

// returns if the current line is open (clerk is on break or not)
bool LineSelectionWhiteboard::isLineOpen(int lineNum){
	if (lineOpen[lineNum] == 1)
		return true;
	else
		return false;
} 		

// returns the number of customers that still need to be reshuffled
int LineSelectionWhiteboard::getNumReshuffle(){
	return numReshuffle;
} 			
    
// sets the length of a specific line
void LineSelectionWhiteboard::setLineLength(int lineNum, int lineLength){
	currLineLength[lineNum] = lineLength;
} 

// sets if the current line is open (clerk is on break or not)
void LineSelectionWhiteboard::setLineOpen(int lineNum, bool value){
	if (value)
		lineOpen[lineNum] = 1;
	else
		lineOpen[lineNum] = 0;
}

// sets the number of customers that still need to be reshuffled
void LineSelectionWhiteboard::setNumReshuffle(int value){
	numReshuffle = value;
}

// increases the given line length by 1
void LineSelectionWhiteboard::incrementLineLength(int lineNum) {
	currLineLength[lineNum] = currLineLength[lineNum]+1;
}
// decreases the given line length by 1
void LineSelectionWhiteboard::decrementLineLength(int lineNum) {
	currLineLength[lineNum] = currLineLength[lineNum]-1;
}

int LineSelectionWhiteboard::selectShortestLine() {
   int currShortest = 100;
   int currShortestInd = -1;
   for (int i = 0; i < numLines; i++) {
		if (this->isLineOpen(i) && this->isLineOpen(i) && this->getLineLength(i) < currShortest) {
			currShortestInd = i;
			currShortest = this->getLineLength(i);
		}
   }
   return currShortestInd;
}
